<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div class="app">
        <input type="text" v-fk_modul.trim="msg" />
        <button @click="msg='蔡徐坤'">changeMsg</button>
        <h2>msg:{{msg}}</h2>
      </div>
      <script>
        Vue.directive('fk_modul', (el, binding, vnode) => {
          binding.eve = 'input'
          if (binding.modifiers.trim) {
              el.addEventListener(binding.eve, function () {
                vnode.context[binding.expression] = el.value.trim()
              })
              el.value = binding.value.trim()
          }else{
              el.addEventListener(binding.eve, function () {
                vnode.context[binding.expression] = el.value
              })
              el.value = binding.value
          }
          
        })
        const app = new Vue({
          el: '.app',
          data: {
            msg: '',
          }
        })
      </script>
      
</body>
</html>